{% extends "layout.html" %}
{% block content %}
    <div class="x-nav">
      <div class="layui-col-md6">
          <button class="layui-btn" onclick="x_admin_show('添加数据点','dataItem-edit.html?channel_id='+channel_id,800,400)"><i class="layui-icon"></i>添加数据点</button>
      </div>
      <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
    </div>
    <div class="x-body layui-anim layui-anim-up">
      <table id="dataItemList" class="layui-table" lay-filter="dataItem">
      </table>
      <script type="text/html" id="dataItemBar">
        <div class="layui-btn-group">
          <button type="button" class="layui-btn layui-btn-sm" lay-event="edit"><i class="layui-icon">&#xe642;</i></button>
          <button type="button" class="layui-btn layui-btn-sm"lay-event="del"><i class="layui-icon">&#xe640;</i></button>
        </div>
      </script>    
    </div>
    <script>
        var dataItemTitle;
        var channel_id=GetQueryString('channel_id');
        $(function  () {
            layui.use(['table','form'], function(){
            var table = layui.table;
            table.render({
                elem: '#dataItemList'
                ,height:'full-100'
                ,url:'./dataItemList?channel_id='+channel_id
                ,cols:[[
                {type:'checkbox', fixed: 'left'}
                ,{title:'ID',field:'dataItem_id',align: 'center', sort: true, fixed: true}
                ,{title:'标签',field:'label',align: 'center'}
                ,{title:'数据类型',field:'data_type',align: 'center', sort: true}
                ,{fixed: 'right', align:'center', toolbar: '#dataItemBar'}
                ]]
                ,page: true
                ,limit:100
                ,limits:[100,200,500]
            });
            //监听表格复选框选择
            table.on('checkbox(dataItem)', function(obj){
            });
            //监听工具条
            table.on('tool(dataItem)', function(obj){
                var data = obj.data;
                switch(obj.event){
                case 'edit':
                    x_admin_show('编辑通道','dataItem-edit.html?channel_id='+obj.data.channel_id+'&dataItem_id='+obj.data.dataItem_id,800,400);
                    break;
                case 'del':
                    layer.confirm('真的删除行么', function(index){
                    // console.log(obj.data);
                    data={'dataItem_id':obj.data.dataItem_id};
                    $.ajax({
                        url:'deldataItem',
                        type:'POST',
                        data:data,
                        success:function(data){
                            // console.log(data);
                            if(data.code==0)obj.del();
                        }
                    });
                    obj.del();
                    layer.close(index);
                    });
                    break;
                default:
                }
            });
            });
        })
    </script>
{% endblock %}